package com.net.oil.gaode.adpater;

import android.content.Context;
import android.content.Intent;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.amap.api.services.route.BusPath;
import com.amap.api.services.route.BusRouteResult;
import com.net.oil.R;
import com.net.oil.gaode.BusRouteDetailActivity;
import com.net.oil.gaode.util.AMapUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者：lch
 * 时间：2018/4/15 0015:上午 10:22
 * 邮箱：245850413@qq.com
 * 说明：
 */

public class BusRoutRecyclerViewAdapter extends RecyclerView.Adapter<BusRoutRecyclerViewAdapter.ViewHolder> {

    private Context context;
    private LayoutInflater inflater;

    private List<BusPath> mBusPathList;
    private BusRouteResult mBusRouteResult;

    public BusRoutRecyclerViewAdapter(Context context, BusRouteResult busrouteresult) {
        this.context = context;
        inflater = LayoutInflater.from(context);

        mBusRouteResult = busrouteresult;
        mBusPathList = busrouteresult.getPaths();
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.bus_rout_recycler_view_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final BusPath item = mBusPathList.get(position);
        holder.busPathTitle.setText(AMapUtil.getBusPathTitle(item));
        holder.busPathDes.setText(AMapUtil.getBusPathDes(item));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context.getApplicationContext(),
                        BusRouteDetailActivity.class);
                intent.putExtra("bus_path", item);
                intent.putExtra("bus_result", mBusRouteResult);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mBusPathList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.bus_path_title)
        TextView busPathTitle;
        @BindView(R.id.bus_path_des)
        TextView busPathDes;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
